package com.递归2;

/**
 * {1, -1, 3, -8, 10, 9}返回最大值10
 */
public class 递归求解数组中得最大值 {
    public static class Solution{
        public static int max(int[] nums){
            return forMax(nums,0,nums[0]);
        }

        private static int forMax(int[] nums, int i, int max) {
            if(i>=nums.length-1){
               return max<nums[i] ? nums[i] : max;
            }
            max = max<nums[i] ? nums[i] : max;
            return forMax(nums,++i,max);
        }

        public static void main(String[] args) {
            System.out.println(max(new int[]{2,1}));
        }
    }
}
